package dyyx.util;

import java.util.Properties;

import org.apache.commons.lang3.StringUtils;

public class ConfigUtil{
	
	
	private static final String CONFIG = "config.properties";

    private static  PropertiesResult propResult = null;
    
    static{
    	PropertiesResult pr = CommUtil.readProperties(CONFIG);
    	propResult = pr;
    }
    
    
    public static Properties getConfig(){
    	return propResult.properties;
    }
    
    
    public static String get(String key){
    	if(StringUtils.isBlank(key)){
    		return null;
    	}
    	String value = propResult.properties.getProperty(key);
    	if(value!=null){
    		value = value.trim();
    	}
    	return value;
    }
    
    public static int getInt(String key){
    	if(StringUtils.isBlank(key)){
    		return 0;
    	}
    	
    	return CommUtil.getInt(get(key));
    }
    
    public static long getLong(String key){
    	if(StringUtils.isBlank(key)){
    		return 0;
    	}
    	
    	return CommUtil.getLong(get(key));
    }
    
    public static String getInfo(){
    	StringBuilder sb = new StringBuilder();
    	
    	sb.append("name="+propResult.name);
    	sb.append(",type="+propResult.type);
    	sb.append(",num="+propResult.properties.size());

    	sb.append(",url="+propResult.url);
    	
    	return sb.toString();
    }

}
